package com.yunbao.hujin.mychoosealbum.utils;

import android.content.Context;

import com.bumptech.glide.BitmapRequestBuilder;
import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.yunbao.hujin.mychoosealbum.R;

/**
 * Created by Administrator on 2017/11/17.
 */

public class GlideUtil {


    public static DrawableRequestBuilder show(Context context, String path) {
        return Glide.with(context)
                .load(path)
                .placeholder(R.drawable.bg_loading)
                .error(R.drawable.bg_loading);
    }


    public static DrawableRequestBuilder showLocalImg(Context context, Integer resourceId) {
        return Glide.with(context)
                .load(resourceId)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
    }

    public static DrawableRequestBuilder showCenterCrop(Context context, String path) {
        return Glide.with(context)
                .load(path)
                .centerCrop()
                .placeholder(R.drawable.bg_loading)
                .error(R.drawable.bg_loading);
    }


    /**
     * 查看相册大图时
     */
    public static BitmapRequestBuilder showImgCenterBitmap(Context context, String path) {
        return Glide.with(context)
                .load(path)
                .asBitmap()
                .fitCenter()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .error(R.mipmap.load_failed);
    }


    /**
     * 清理 glide 个人缓存
     */
    public static void clearGlideMemory(Context context) {
        Glide.get(context)
                .getBitmapPool()
                .clearMemory();
    }

}
